import { defineStore} from 'pinia'
import axios from 'axios'
import { nanoid } from 'nanoid'
import {ref,reactive,computed} from 'vue'
export const useLoveStore = defineStore('love',() => {
 
  // list 相当于state
  const list = reactive(JSON.parse(localStorage.getItem('list') as string) || [])
  const sum= ref(2)
  // getTalk函数相当于actions
  async function getTalk () {
    let { data:{content:title} } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
    list.unshift({
      id: nanoid(),
      title
    })
  }

  const bigSum = computed(()=>{
    return sum.value*2
  })
  return {
    list, getTalk,bigSum
  }
})






